/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import item.Item;
import item.ItemInfo;
import item.ItemList;
import java.sql.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import myJPA.Model;
import transactions.Rental;
import user.Customer;
import user.Employee;

/**
 *
 * @author ZIZI
 */
public class ManageItemList {
    

 public static void main(String[] args)
    {
        //TEST 1
        if(addNewItemTest())
            System.out.println("Test 1 successful");
        else
            System.out.println("Test 1 failed");
        
        
        //TEST 2
        if(removeItemTest())
            System.out.println("Test 2 successful");
        else
            System.out.println("Test 2 failed");
        
         if(addcopyTest())
            System.out.println("Test 3 successful");
        else
            System.out.println("Test 3 failed");
         
       if(removecopyTest())
            System.out.println("Test 4 successful");
        else
            System.out.println("Test 4 failed");
       
       if(reportItemTest())
            System.out.println("Test 5 successful");
        else
            System.out.println("Test 5 failed");
         
       if(setRentalRatetest())
            System.out.println("Test 6 successful");
        else
            System.out.println("Test 6 failed");
       
        if(reportOverdueTest())
            System.out.println("Test 7 successful");
        else
            System.out.println("Test 7 failed");
         
    }
    
    public static boolean addNewItemTest()
    {
        //First create the item object
        Item item= new Item("savage", 3, "Movie");
        ItemList.addItem(item);
        
        item.refresh();
        
        Item saved = (Item) Model.getEntityManager().find(Item.class, item.getId());
        if(item.equals(saved))
            return true;
        return false;
        
    }
    

    
    public static boolean removeItemTest()
    {
        //First create the item object
        Item item= new Item("savage", 3, "Movie");
        //save the item
        item.save();
        
        item.refresh();
        
        ItemList.removeItem(item);
        
        Item saved = (Item) Model.getEntityManager().find(Item.class, item.getId());
        
        if(saved == null)
            return true;
        return false;
        
    }


        public static boolean addcopyTest()
    {
        //First create the item object
        Item item= new Item("savage", 3, "Movie");
        //save the item
        item.save();
        
        item.refresh();
        
        ItemList.addCopy(item);
        
        Item saved = (Item) Model.getEntityManager().find(Item.class, item.getId());
        
        if(saved == null)
            return true;
        return false;
    
    }
    
      
   public static boolean removecopyTest()
    {
        //First create the item object
        Item item= new Item("batman", 6, "Movie");
        //save the item
        item.save();
        
        item.refresh();
        
        ItemList.RemoveCopy(item);
        
        Item saved = (Item) Model.getEntityManager().find(Item.class, item.getId());
        
        if(saved == null)
            return true;
        return false;
    
    }
    
    public static boolean reportItemTest()
    {
        String result=null;
        //First create the item object
        Item item= new Item("batman", 6, "Movie");
        //save the item
        item.save();
        
        item.refresh();
        
        result= ItemList.ReportItem(item);
        
        Item saved = (Item) Model.getEntityManager().find(Item.class, item.getId());
        System.out.println(result);
        if(saved == null)
        
        return true;
                       
        return false;
    
    }
    
    
     public static boolean setRentalRatetest()
    {
       
        Customer customer = new Customer("Saad", "Khalil", "rabat, Maroc", "0661601996", new Date(2012, 11, 25));
        customer.save();
        customer.refresh();
        Item item = new Item("Skyfall", 10, "Movie");
        item.save();
        item.refresh();
        Employee employee = new Employee("Hamid", "El kasri", "Casablanca, Maroc", "0665778813", "siHamid", "Clerk", "salam");
        employee.save();
        employee.refresh();
        
        ItemInfo videoInfo = new ItemInfo("Movie", 10, 15, 20);
        videoInfo.save();
        ItemInfo videoGameInfo = new ItemInfo("VideoGame", 12, 15, 20);
        videoGameInfo.save();
        
       ItemList.SetRentalPeriod(20, "Movie");
        
        Item saved = (Item) Model.getEntityManager().find(Item.class, item.getId());
        
        if(saved == null)
        
        return true;
                       
        return false;
    
    }
    
    
    public static boolean reportOverdueTest(){
        
        String result=null;
        Customer customer = new Customer("Saad", "Khalil", "rabat, Maroc", "0661601996", new Date(2012, 11, 25));
        customer.save();
        customer.refresh();
        Item item = new Item("Skyfall", 10, "Movie");
        item.save();
        item.refresh();
        Employee employee = new Employee("Hamid", "El kasri", "Casablanca, Maroc", "0665778813", "siHamid", "Clerk", "salam");
        employee.save();
        employee.refresh();
        
        ItemInfo videoInfo = new ItemInfo("Movie", 10, 15, 20);
        videoInfo.save();
        ItemInfo videoGameInfo = new ItemInfo("VideoGame", 12, 15, 20);
        videoGameInfo.save();
        
        Calendar c1 = new GregorianCalendar(2012, 10, 5);
        Calendar c2 = new GregorianCalendar(2012, 10, 20);
        Rental rental = new Rental(new Date(c1.getTimeInMillis()), new Date(c2.getTimeInMillis()), customer, item, employee);
        
        rental.save();
        
        result=ItemList.ReportOverdue();
        
         System.out.println(result);
        Item saved = (Item) Model.getEntityManager().find(Item.class, item.getId());
       
        if(saved == null)
        
        return true;
                       
        return false; 
    }
    
}
